// 个人博客后台管理模块处理函数

const utils = require("../../common/utils")
const server = require("../../server/blog/admin")

// 添加技能
exports.addSkill = (req, res) => {
    const data = req.body
    server.addSkill(data).then(result => {
        return res.cc(result, 200)
    }).catch(e => {
        return res.cc(e)
    })
}

// 删除技能
exports.deleteSkill = (req, res) => {
    let id = req.query.id
    server.deleteSkill(id).then(result => {
        return res.cc(result, 200)
    }).catch(e => {
        return res.cc(e)
    })
}

// 修改技能
exports.updateSkill = (req, res) => {
    const data = req.body
    server.updateSkill(data).then(result => {
        return res.cc(result, 200)
    }).catch(e => {
        return res.cc(e)
    })
}

// 获取技能
exports.getSkill = (req, res) => {
    server.getSkill().then(result => {
        return res.send({
            code: 200,
            message: "获取成功",
            data: result
        })
    }).catch(e => {
        return res.cc(e)
    })
}

// 添加分类
exports.addCategory = (req, res) => {
    const data = req.body
    server.addCategory(data).then(result => {
        return res.cc(result, 200)
    }).catch(e => {
        return res.cc(e)
    })
}

// 删除分类
exports.deleteCategory = (req, res) => {
    let id = req.query.id
    let type = req.query.type
    server.deleteCategory(id, type).then(result => {
        return res.cc(result, 200)
    }).catch(e => {
        return res.cc(e)
    })
}

// 修改分类
exports.updateCategory = (req, res) => {
    const data = req.body
    server.updateCategory(data).then(result => {
        return res.cc(result, 200)
    }).catch(e => {
        return res.cc(e)
    })
}

// 获取分类
exports.getCategory = (req, res) => {
    let type = req.query.type
    server.getCategory(type).then(result => {
        return res.send({
            code: 200,
            message: "获取成功",
            data: result
        })
    }).catch(e => {
        return res.cc(e)
    })
}

// 添加项目
exports.addProject = (req, res) => {
    const data = req.body
    server.addProject(data).then(result => {
        return res.cc(result, 200)
    }).catch(e => {
        return res.cc(e)
    })
}

// 删除项目
exports.deleteProject = (req, res) => {
    let id = req.query.id
    server.deleteProject(id).then(result => {
        return res.cc(result, 200)
    }).catch(e => {
        return res.cc(e)
    })
}

// 修改项目
exports.updateProject = (req, res) => {
    const data = req.body
    server.updateProject(data).then(result => {
        return res.cc(result, 200)
    }).catch(e => {
        return res.cc(e)
    })
}

// 获取项目
exports.getProject = (req, res) => {
    let pageSize = req.query.pageSize || 20
    let pageNum = req.query.pageNum
    let category_id = req.query.category_id
    server.getProject(category_id, pageNum, pageSize).then(result => {
        return res.send({
            code: 200,
            message: "获取成功",
            data: result
        })
    }).catch(e => {
        return res.cc(e)
    })
}